package com.ruoyi.stock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.StockMemberRule;
import com.ruoyi.stock.service.IStockMemberRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员规则Controller
 * 
 * @author ruoyi
 * @date 2024-12-30
 */
@RestController
@RequestMapping("/stock/stockmemberrule")
@Api( tags = "会员套餐")
public class StockMemberRuleController extends BaseController
{
    @Autowired
    private IStockMemberRuleService stockMemberRuleService;

    /**
     * 查询会员规则列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "套餐查询")
    public TableDataInfo list(StockMemberRule stockMemberRule)
    {
        startPage();
        List<StockMemberRule> list = stockMemberRuleService.selectStockMemberRuleList(stockMemberRule);
        return getDataTable(list);
    }

    /**
     * 导出会员规则列表
     */
    @Log(title = "会员规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockMemberRule stockMemberRule)
    {
        List<StockMemberRule> list = stockMemberRuleService.selectStockMemberRuleList(stockMemberRule);
        ExcelUtil<StockMemberRule> util = new ExcelUtil<StockMemberRule>(StockMemberRule.class);
        util.exportExcel(response, list, "会员规则数据");
    }

    /**
     * 获取会员规则详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stockMemberRuleService.selectStockMemberRuleById(id));
    }

    /**
     * 新增会员规则
     */
    @Log(title = "会员规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockMemberRule stockMemberRule)
    {
        return toAjax(stockMemberRuleService.insertStockMemberRule(stockMemberRule));
    }

    /**
     * 修改会员规则
     */
    @Log(title = "会员规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockMemberRule stockMemberRule)
    {
        return toAjax(stockMemberRuleService.updateStockMemberRule(stockMemberRule));
    }

    /**
     * 删除会员规则
     */
    @Log(title = "会员规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stockMemberRuleService.deleteStockMemberRuleByIds(ids));
    }
}
